var windowName = "matterLog";
var Page
var MatterLog = new List()
apiready = function(){
    onWindowShow(function () {
        getData(Page)
    })
    onWindowHide(function () {
    })
    console.log("index page is OK");

    Page = createVM("#Page",{
        //页面数据
        tab:0,
        sites:[],
        list:[],
        types:[],
        matters:[],
        en:{}
    },{
        //页面方法
        "init":function () {
            var _this = this;
            startPullDownRefresh();
            MatterLog.setUrl("/app/matter/log")
                .setCbFunc(function (data) {
                    _this.list = data
                    stopPullDownRefresh();
                    stopPullUpLoadMore();
                }).getList()
        },
        OnPullDownRefresh:function () {
            startPullDownRefresh();
            MatterLog.reload()
        },
        OnPullUpLoadMore:function () {
            if (this.tab === 0) {
                startPullUpLoadMore();
                MatterLog.getList()
            }
        },
        submit:function() {
            var _this = this
            this.$refs.form.validate().then((result) => {
                if (result){
                    var form = createForm(this.en);
                    apiPost("/app/matter/log/add",form,function (res) {
                        // log(res)
                        MatterLog.reload()
                        _this.tab = 1
                        showToast(res.message)
                    })

                }else{
                    showToast("请检查输入")
                }
            });
        },
    })

    Page.init()

}

function getData(_this) {
    apiGet("/app/matter/log/add",{},function (res) {
        _this.types = res.data.type
        _this.matters = res.data.matters
        _this.en = res.data.en
        _this.sites = res.data.sites
    })
}